package com.cne.gmail.Gmail.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class WebSocketService {

@Autowired
SimpMessagingTemplate template;


    /**
     * 广播
     * 发给所有在线用户
     *
     * @param msg
     */
    public void sendMsg(WiselyResponse msg) {
        this.template.convertAndSend("/topic/getResponse", msg);
    }

    /**
     * 发送给指定用户
     * @param users
     * @param msg
     */
    public void send2Users(List<String> users, WiselyResponse msg) {
        users.forEach(userName -> {
            template.convertAndSendToUser(userName, Constant.P2PPUSHPATH, msg);
        });
    }
    public void send2User(String userId,WiselyResponse msg) {
      template.convertAndSendToUser(userId,"/msg",msg);
    }
}